package LeetCode.LeetCode2;

/**
 * @author lumin
 * @date 2022/05/26 16:18
 **/
public class Num1221 {
    public int balancedStringSplit(String s) {
        int[] arr = new int[s.length()];
        for(int i = 0;i < arr.length;i++){
            if(s.charAt(i) == 'L'){
                arr[i] = 1;
            }else{
                arr[i] = -1;
            }
        }
        int count = 0;
        int sum = arr[0];
        for(int i = 1;i < arr.length;i++){
            sum += arr[i];
            if(sum == 0){
                count++;
            }
        }
        return count;
    }
}